const { goodList } = require("../../../utils/api");

// pages/searchpage/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    inputValue: '',
    pointList: []
  },
  handleInput: function (e) {
    this.setData({
      inputValue: e.detail.value
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      inputValue: options.search
    })
    this.getGoodsList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  onGoodsDetail(e) {
    wx.navigateTo({ url: `/packageA/pages/goodsdetail/index?goodsid=${e.currentTarget.dataset.item.id}` })
  },

  async getGoodsList() {
    let params = {
      sorttype: "",
      descasc: "",
      search: this.data.inputValue,
    }
    await goodList(params).then((res) => {

      if (res.errcode == 0) {
        this.setData({
          pointList: res.data.goodslist.goods
        })

      } else {
        wx.showToast({
          title: res.errmsg,
          icon: 'none',
        });

      }
    })

  },

  onBack() {
    wx.navigateBack({
      delta: 1
    })
  },

  onclear() {
    this.getGoodsList()


  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },



})